import 'package:sow_app_core/sow_app_core.dart';
import 'package:test/test.dart';

import 'package:sow_app_mock/sow_app_mock.dart';

void main() {
  group('login controller test group', () {
    final MockLoginPresenter presenter = MockLoginPresenter();
    final controller = MockLoginController(presenter, MockRestClient());
    test("should present token when invoke userLogin", () async {
      presenter.username = "17612345678";
      presenter.password = "bar";
      presenter.captchaCode = "hello";
      await controller.userLogin();
      await Future.doWhile(() => presenter.flag = false);
    });
    test("should present ServerException when invoke userLogin", () async {
      presenter.username = "foo";
      presenter.password = "bar";
      presenter.captchaCode = "hello";
      try {
        await controller.userLogin();
        await Future.doWhile(() => presenter.flag = false);
      } catch (e) {
        expect(e, isA<ServerException>());
      }
    });
    test("should execute normal when invoke getChapterContent", () async {
      controller.clearUser();
      await Future.doWhile(() => presenter.flag = false);
    });
  });
}
